package com.ufox.controller;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ufox.entity.Products;
import com.ufox.entity.Result;
import com.ufox.entity.Type;
import com.ufox.req.ProductsCondREQ;
import com.ufox.service.ITypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.sql.ResultSet;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 优狐科技-www.hbufox.com
 * @since 2022-06-09
 */
@RestController
@RequestMapping("/type")
public class TypeController {

    @Autowired
    private ITypeService typeService;

    @PostMapping
    public Result findAll(){
        List<Type> list = typeService.list();
        return Result.ok(list);
    }

    @GetMapping("/{page}/{size}")
    public Result findTypeList(@PathVariable int page, @PathVariable int size) {
        Page<Type> pageInfo = new Page<>(page, size);
        LambdaQueryWrapper<Type> wrapper = new LambdaQueryWrapper<>();
        Page<Type> typeList = typeService.page(pageInfo,wrapper);
        return Result.ok(typeList);
    }

    @GetMapping("/prodsList")
    public Result prodsList(){
        List<Type> list = typeService.prodsList();
        return Result.ok(list);
    }

    @GetMapping("/{id}")
    public Result getById(@PathVariable Integer id) {
        Type type = typeService.getById(id);
        return Result.ok(type);
    }

    //添加  或 修改
    @PostMapping("/addOrUpdateType")
    public Result addOrUpdateType(@RequestBody Type type) {
        boolean b = typeService.saveOrUpdate(type);
        return  (b ? Result.ok() : Result.error(""));
    }
}

